home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / comm / misc / zvm1_19.lha / handlecall.zvm < prev    next >
Text File  |  1993-04-24  |  10KB  |  389 lines

  1. /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
  2. /* DO NOT EDIT ANYTHING THAT IS NOT PART OF THE USER-CODE SECTION!!! */
  3. /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  4.  
  5. /* Called when zvm wants to handle a call */
  6. /* You can assume that zvm will answer the telephone for you
  7.     it will hang up for you after you're done.  You do
  8.     need to tell it to listen.  If, at any time, you would
  9.     like to handle a fax, do something like call answerFax() */
  10.  
  11. /* we want results! */
  12. options results
  13.  
  14. /* We want to trap on these things, to help us debug */
  15. signal on halt
  16. signal on novalue
  17. signal on syntax
  18. signal on break_c
  19.  
  20. /* Set up modem stuff */
  21. call doInitializations
  22.  
  23. /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
  24. /*                       BEGIN USER-CODE SECTION                        */
  25.  
  26. status = handleVoice()
  27.  
  28. if status = status.faxDetected then do
  29.     status = answerFax()
  30. end
  31.  
  32. /* finish up */
  33. call flushPhoneBuffer()
  34. call playVoice('voice:voices/Goodbye')
  35. /* make sure zvm doesn't hang up or anything, so we send
  36.     him a listen */
  37. call listen()
  38. exit 20
  39.  
  40. handleVoice: procedure expose status. mode.
  41.     status = status.Normal;
  42.  
  43.     /* get a C compatible time */
  44.     actualTime = cTime()
  45.  
  46.     /* make a unique file name for our incoming message */
  47.     fileName = 'voice:voicein/vm' || actualTime
  48.  
  49.     call flushPhoneBuffer()
  50.     status = playVoice('voice:voices/Wait For Beep')
  51.     if status = status.keyDetected then signal handleVoicePressedKey
  52.     if status ~= status.normal then return status
  53.  
  54.     status = playBeep(3000, 0, 5)
  55.     if status = status.keyDetected then signal handleVoicePressedKey
  56.     if status ~= status.normal then return status
  57.  
  58.     call time('R') /* reset ellapsed timer */
  59.  
  60.     status = recordVoice(fileName)
  61.     call addLogEntry(fileName, actualTime, trunc(time('E')))
  62.  
  63.     if status = status.keyDetected then signal handleVoicePressedKey
  64.  
  65.     return status
  66.  
  67. handleVoicePressedKey:
  68.     status = pressedKeyDuringRecord()
  69.     return status
  70.  
  71. pressedKeyDuringRecord: procedure expose status. mode.
  72.     if hasFax() then
  73.         status = presentMenu(1,'voice:voices/Retrieve or Fax','voice:voices/Bad Choice',7,'29*',3)
  74.     else
  75.         status = presentMenu(1,'voice:voices/Retrieve or Fax','voice:voices/Bad Choice',7,'9*',3)
  76.  
  77.     if status ~= status.normal then return status
  78.  
  79.     select
  80.         when choice = '2' then status = status.faxDetected
  81.         when choice = '9' then status = retrieveMessages()
  82.         when choice = '*' then status = status.timedOut
  83.     end
  84.  
  85.     return status
  86.  
  87. retrieveMessages: procedure expose status. mode.
  88.     status = presentMenu(4,'voice:voices/Enter Password','voice:voices/Bad Password',7,password(),3)
  89.     if status ~= status.normal then return status
  90.  
  91.     status = playMessages()
  92.  
  93.     return status
  94.  
  95. playMessages: procedure expose status. mode.
  96.     voiceLogCount = getNumVoiceMessages()
  97.  
  98.     if voiceLogCount > 0 then do i = 0 to voiceLogCount - 1
  99.         call playBeep(3000, 0, 5)
  100.         status = playOrDeleteMessage(i)
  101.         if (status ~= status.normal) then signal playMessagesDone
  102.     end
  103.     
  104.     call flushPhoneBuffer()
  105.     status = playVoice("voice:voices/No Messages")
  106.  
  107. playMessagesDone:
  108.     return status
  109.  
  110. /* */
  111.  
  112. playOrDeleteMessage: procedure expose status. mode.
  113.     parse arg voiceLogEntry
  114.  
  115. playOrDeleteMessageAgain:
  116.     call flushPhoneBuffer()
  117.     call playVoice(getLogEntryFileName(voiceLogEntry))
  118.     call flushPhoneBuffer()
  119.  
  120.     status = presentMenu(1, 'voice:voices/Play or Delete', 'voice:voices/Bad Choice', 7, '123*', 3)
  121.     if status ~= status.normal then return status
  122.  
  123.     select
  124.         when choice = '1' then do
  125.             call setLogEntryStatus(voiceLogEntry, 'd') /* delete */
  126.             status = status.normal
  127.         end
  128.         when choice = '2' then status = status.normal /* keep the message */
  129.         when choice = '3' then signal playOrDeleteMessageAgain
  130.         when choice = '*' then status = status.timedOut
  131.     end
  132.  
  133.     return status
  134.  
  135. /*                         END OF USER-CODE SECTION                       */
  136. /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  137.  
  138. /*-------------------------HANDS OFF--------------------------------------*/
  139. /* DON'T TOUCH THIS STUFF.  IF YOU FIX SOMETHING HERE, TELL ME ABOUT IT   */
  140.  
  141. /* This function gives you a simple way of presenting an N key menu
  142.     to the caller
  143.  
  144.     ARGS:  numKeys choiceFileName badChoiceFileName timeOut validChoices
  145.     numBadChoices
  146.  
  147.     numKeys = number of keys wanted
  148.     choiceFileName = file name of the menu
  149.     badChoiceFileName = what to say if caller enters a bad choice
  150.     timeOut = number of seconds allowed before timing out
  151.     validChoices = list of characters that are valid choices
  152.     numBadChoices = number of times you want to present the menu before exiting
  153.  
  154.     RETURNS:  status, choice = valid key
  155. */
  156.  
  157. presentMenu: procedure expose choice status. mode.
  158.     parse arg numKeys,choiceFileName,badChoiceFileName,timeOut,validChoices,numBadChoices .
  159.  
  160.     timesAround = numBadChoices;
  161.  
  162.     do timesAround = numBadChoices to 1 by -1
  163.         status = playVoice(choiceFileName)
  164.  
  165.         if status > status.keyDetected then signal presentMenuDone;
  166.  
  167.         status = readNKeys(numKeys, timeOut)
  168.  
  169.         if status = status.timedOut then do
  170.             call flushPhoneBuffer()
  171.             status = playVoice('voice:voices/Timed Out')
  172.             iterate
  173.         end
  174.         if status ~= status.normal then signal presentMenuDone;
  175.  
  176.         choice = keys
  177.         if pos(choice, validChoices) = 0 then do
  178.             call flushPhoneBuffer()
  179.             status = playVoice(badChoiceFileName)
  180.             iterate
  181.         end
  182.  
  183.         return status.normal
  184.     end
  185.  
  186.     status = status.timedOut
  187. presentMenuDone:
  188.     return status
  189.  
  190. /*----------------------------------------------------------------------*/
  191. /*    Here are the encapsulated functions.  They're responsible for
  192.     communicating with ZVM.  Don't edit or touch them, except for
  193.     bug fixes.
  194. */
  195.  
  196. playVoice:  procedure expose status. mode.
  197.     parse arg fileName
  198.     address voicemail1 'playVoice' fileName
  199.     return rc
  200.  
  201. addLogEntry: procedure expose status. mode.
  202.     parse arg fileName, actualTime, duration
  203.     address voicemail1 'addLogEntry' fileName ',' actualTime ',' duration
  204.     return rc
  205.  
  206. setLogEntryStatus: procedure expose status. mode.
  207.     parse arg logEntryNumber, logEntryStatus
  208.     select
  209.         when logEntryStatus = ' ' then ls = 0
  210.         when logEntryStatus = 'a' then ls = 1
  211.         when logEntryStatus = 'd' then ls = 2
  212.         otherwise ls = -1
  213.     end
  214.     address voicemail1 'setLogEntryStatus' logEntryNumber ',' ls
  215.     return rc
  216.  
  217. getLogEntryData: procedure expose status. mode.
  218.     parse arg logEntryNumber
  219.     address voicemail1 'getLogEntryData' logEntryNumber
  220.     return result
  221.  
  222. getLogEntryFileName: procedure expose status. mode.
  223.     parse arg logEntryNumber
  224.     address voicemail1 'getLogEntryFileName' logEntryNumber
  225.     return result
  226.  
  227. getNumVoiceMessages: procedure expose status. mode.
  228.     address voicemail1 'getNumVoiceMessages'
  229.     return result
  230.  
  231. recordVoice:  procedure expose status. mode.
  232.     parse arg fileName
  233.     address voicemail1 'recordVoice' fileName
  234.     return rc
  235.  
  236. password: procedure expose status. mode.
  237.     address voicemail1 'password'
  238.     return result
  239.  
  240. hasFax: procedure expose status. mode.
  241.     address voicemail1 'hasfax'
  242.     return result
  243.  
  244. playBeep:  procedure expose status. mode.
  245.     parse arg tone1, tone2, duration
  246.     address voicemail1 'playBeep' tone1 ',' tone2 ',' duration
  247.     return rc
  248.  
  249. readNKeys:  procedure expose status. keys mode.
  250.     parse arg numKeys, timeOut
  251.     address voicemail1 'readNKeys' numKeys ',' timeOut
  252.     if rc = status.normal then keys = result
  253.     return rc
  254.  
  255. read1Key:  procedure expose status. key mode.
  256.     parse arg timeOut
  257.     address voicemail1 'read1Key' timeOut
  258.     if rc = status.normal then key = result
  259.     return rc
  260.  
  261. readKeysUntil: procedure expose status. keys mode.
  262.     parse arg terminatingCharacter, maxCharacters, timeOut
  263.     address voicemail1 'readKeysUntil' terminatingCharacter ',' maxCharacters ',' timeOut
  264.     if rc = status.normal then keys = result
  265.     return rc
  266.  
  267. readLine: procedure expose status. line mode.
  268.     parse arg timeOut
  269.     address voicemail1 'readLine' timeOut
  270.     if rc = status.normal then line = result
  271.     return rc
  272.  
  273. writeLine: procedure expose status. mode.
  274.     parse arg line
  275.     address voicemail1 'writeLine' line
  276.     return rc
  277.  
  278. /* the 'assumeUnknownMode' is to make sure that any use of a voice command WILL
  279.     cause ZVM to hang up the line, reset the modem, then do its stuff */
  280.  
  281. dropLine: procedure expose status. mode.
  282.     address voicemail1 'assumeUnknownMode'
  283.     address voicemail1 'requireMode' mode.commandMode
  284.     return rc
  285.  
  286. atCommands: procedure expose status. mode.
  287.     address voicemail1 'assumeUnknownMode'
  288.     address voicemail1 'requireMode' mode.connectedMode
  289.     return rc
  290.  
  291. use19200: procedure expose status. mode.
  292.     address voicemail1 'setserial'
  293.     return rc
  294.  
  295. flushPhoneBuffer:  procedure expose status. mode.
  296.     address voicemail1 'flushPhoneBuffer'
  297.     return status.normal
  298.  
  299. listen: procedure expose status. mode.
  300.     address voicemail1 'listen'
  301.     return status.normal
  302.  
  303. answerFax: procedure expose status. mode.
  304.     address voicemail1 'answerFax'
  305.     return rc
  306.  
  307. cTime: procedure expose status. now mode.
  308.     address voicemail1 'ctime'
  309.     return result
  310.  
  311. displayError: procedure expose status. mode.
  312.     parse arg error
  313.     address voicemail1 'displayError' error
  314.     return status.normal
  315.  
  316. displayStatus: procedure expose status. mode.
  317.     parse arg status
  318.     address voicemail1 'displayStatus' status
  319.     return status.normal
  320.  
  321. /* Effectively unlistens also! */
  322. setLastError: procedure expose status. mode.
  323.     parse arg status, error
  324.     address voicemail1 'setLastError' status ',' error
  325.  
  326. /*-----------------------------------------------------------------------*/
  327. /* signal processing */
  328. error:
  329.     say "Error " rc " at line " sigl
  330.     call listen()
  331.     exit 20
  332.  
  333. break_c:
  334. halt:
  335.     say "VoiceMail was stopped manually"
  336.     call listen()
  337.     exit 20
  338.  
  339.  
  340. novalue:
  341.     say "No Value at Line" sigl
  342.     call playVoice('voice:voices/NoValue')
  343.     call listen()
  344.     exit 20
  345.  
  346. syntax:
  347.     say 'Syntax Error at Line' sigl
  348.     call playVoice('voice:voices/SyntaxError')
  349.     call listen()
  350.     exit 20
  351.  
  352.  
  353. /* Initialize everything needed to communicate correctly with ZVM */
  354. doInitializations: procedure expose compression. mode. status. device.
  355.  
  356. /* compressions */
  357. compression.ADPCM2 = 2
  358. compression.ADPCM3 = 3
  359. compression.CELP = 1
  360.  
  361. /* devices */
  362. device.telephoneLine = 2
  363. device.externalMic = 8
  364. device.internalSpeaker = 16
  365.  
  366. /* modem modes */
  367. mode.unknownMode = -1
  368. mode.commandMode = 0
  369. mode.voiceMode = 1
  370. mode.connectedMode = 2
  371. mode.playMode = 3
  372. mode.recordMode = 4
  373.  
  374. /* return statuses from the various commands */
  375. status.normal = 0
  376. status.keyDetected = 1
  377. status.quietDetected = 2
  378. status.silenceDetected = 3
  379. status.faxDetected = 4
  380. status.busyDetected = 5
  381. status.timedOut = 6
  382. status.signalDetected = 7
  383. status.overflow = 8
  384. status.error = 9
  385.  
  386. return
  387.  
  388.  
  389.